package com.syqc.monitor.ui.alarm

import com.syqc.comlib.utils.CacheMMKV
import com.syqc.entity.CarReportEntity
import com.syqc.utils.TimeUtil

/**
 *@Author Jasper
 *@Time   2020/10/20
 *@Desc   todo
 */
class ReportSetModel {
    companion object {
        val instance: ReportSetModel by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
            ReportSetModel()
        }
    }

    private val report: CarReportEntity by lazy {
        CacheMMKV.decodeParcelable("SetReportEntity", CarReportEntity::class.java)
            ?: CarReportEntity()
    }


    fun getSpeed(isAdas: Boolean) = if (isAdas) report.run_speed_adas else report.run_speed

    fun setSpeed(speed: String, isAdas: Boolean) {
        if (isAdas) {
            report.run_speed_adas = speed
        } else {
            report.run_speed = speed
        }
    }


    /**
     * 获取持续时间
     */
    fun getContinueTime(isAdas: Boolean) =
        if (isAdas) report.continue_time_adas else report.continue_time

    fun getContinueTimeFormat(isAdas: Boolean) = if (isAdas) {
        TimeUtil.instance.formatTime(report.continue_time_adas.toInt())
    } else {
        TimeUtil.instance.formatTime(report.continue_time.toInt())
    }

    fun setContinueTime(time: String, isAdas: Boolean) {
        if (isAdas) {
            report.continue_time_adas = time
        } else {
            report.continue_time = time
        }
    }


    fun getNormalAlarmIds() = report.alarm_normal_ids
    fun getNormalLength() = report.alarm_normal_length
    fun getNormalSize() = report.alarm_normal_size
    fun setNormalSize(length: Int) {
        report.alarm_normal_size = length
    }

    fun setNormalAlarmIds(ids: String) {
        report.alarm_normal_ids = ids
        report.alarm_normal_length = if (ids.isEmpty()) 0 else ids.split(",").size
    }

    fun getAdasLength() = report.alarm_adas_length
    fun getAdasSize() = report.alarm_adas_size
    fun setAdasSize(length: Int) {
        report.alarm_adas_size = length
    }

    fun getAdasAlarmIds() = report.alarm_adas_ids
    fun setAdasAlarmIds(ids: String) {
        report.alarm_adas_ids = ids
        report.alarm_adas_length = if (ids.isEmpty()) 0 else ids.split(",").size
    }

    /**
     * 保存参数
     */
    fun saveParams() {
        CacheMMKV.encodeParcelable("SetReportEntity", report)
    }
}